Skip to content

feat(creator-keys): protocol fee bounds, key price, and buy_key payment tests#17

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
Jagadeeshftw:new
Mar 25, 2026
Merged

feat(creator-keys): protocol fee bounds, key price, and buy_key payment tests#17
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
Jagadeeshftw:new

Conversation

@Jagadeeshftw

Copy link
Copy Markdown
Contributor

Summary

Implements explicit validation for configurable protocol fee bounds and adds contract integration tests for invalid creator and insufficient payment paths on buy_key. Closes the scoped work for fee guardrails and marketplace edge-case coverage.

Related issues

Changes

Protocol fee bounds (#13)

  • Introduced fee::PROTOCOL_BPS_MAX (5000 bps / 50%) as the maximum allowed configured protocol share.
  • Added reusable fee::assert_valid_fee_bps(creator_bps, protocol_bps):
    • checked_add for the bps sum
    • creator_bps + protocol_bps == BPS_MAX
    • protocol_bps <= PROTOCOL_BPS_MAX
  • set_fee_config now delegates to assert_valid_fee_bps so all admin fee updates share one validation path.
  • fee::compute_fee_split is unchanged; only stored fee configuration is capped.

Buy flow: price and payment (#16)

  • New persistent DataKey::KeyPrice and set_key_price(admin, price) (price must be positive, admin auth).
  • buy_key now takes payment: i128 and requires a set key price; rejects payment < price with insufficient payment.
  • Unregistered creator behavior remains creator not registered (now covered by tests).

Tests

  • fee_split.rs: success at max protocol bps (5000/5000); panic when protocol bps exceeds cap.
  • buy_key.rs: unregistered creator; insufficient payment; happy path with sufficient payment.

Breaking changes

  • buy_key signature: callers must pass payment: i128.
  • Deployments must call set_key_price before buy_key (or invocations will panic with key price not set).

Update any scripts, clients, or docs that invoke buy_key without the new argument or without initializing key price.

Verification

cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace

Closes #13
Closes #16

- Added `PROTOCOL_BPS_MAX` constant to cap protocol fee settings at 50%.
- Introduced `assert_valid_fee_bps` function to validate fee configurations.
- Updated `buy_key` function to check for sufficient payment against the set key price.
- Implemented `set_key_price` function for setting the price of keys.
- Added tests for key purchase scenarios, including insufficient payment and unregistered creators.
- Created tests for setting fee configurations, including validation for maximum protocol basis points.
@Jagadeeshftw

Copy link
Copy Markdown
Contributor Author

@Chucks1093 kindly review

@drips-wave

drips-wave Bot commented Mar 25, 2026

Copy link
Copy Markdown

@Jagadeeshftw Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093 Chucks1093 merged commit e063c06 into accesslayerorg:main Mar 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for invalid creator and insufficient payment cases Add protocol fee bounds validation

2 participants